package org.lib.postgresqlhello.device;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectKey;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

//@DS("lib2")
public interface DeviceMapper extends BaseMapper<Device> {

	// 直接返回的是 更新条数，而不是id，TODO
	Long addOne(Device device);
	
	Long addOne1(Device device);
	
	Long addOne2(Device device);
	
	Long addOne3(Device device);
	
	Long addOne4(Device device);
	
	// 注解式
	
	@Insert(value = {"INSERT INTO device(sn,name,create_time)",
			"VALUES(#{sn},#{name},now())"})
	Long addOne5(Device device);

	@Insert(value = {"INSERT INTO device(sn,name,create_time)",
			"VALUES(#{sn},#{name},now())"})
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Long addOne6(Device device);
	
	@Insert(value = {"INSERT INTO device(sn,name,create_time)",
			"VALUES(#{sn},#{name},now())"})
	@SelectKey(statement = "SELECT nextval('device_id_seq')", 
		keyProperty = "id", resultType = Long.class, before = false)
	Long addOne7(Device device);
	
	@InsertProvider(type = DeviceProvider.class, method = "addOne8")
	Long addOne8(Device device);

	@InsertProvider(type = DeviceProvider.class, method = "addOne8")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Long addOne9(Device device);
	
	// 根据id更新
	Long updateById3(Long id, Long sn, String name);
	
	// 根据sn删除
	Long deleteBySn(Long sn);
	
}
